import trigger from "../../effect/trigger.js";
import { TriggerOpTypes } from "../../utils.js";

export default function (target, key) {
  // 先是判断该属性是否存在
  const hasKey = target.hasOwnProperty(key);

  // 删除操作
  const result = Reflect.deleteProperty(target, key);

  // 判断是否需要派发更新
  if (hasKey && result) {
    trigger(target, TriggerOpTypes.DELETE, key);
  }

  return result;
}
